package cn.edu.swu.miniwebsvr.core;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Parameter {
    private String method;
    private String url;
    private Map<String, String> urlParams = new HashMap<>();
    private Map<String, String> bodyParams = new HashMap<>();
    private Map<String, String> headers = new HashMap<>();

    public Parameter() {}

    // TODO：【222024321072046/马云山]   Getter和Setter方法
    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Map<String, String> getUrlParams() {
        return Collections.unmodifiableMap(urlParams);
    }

    public void addUrlParam(String key, String value) {
        this.urlParams.put(key, value);
    }

    public Map<String, String> getBodyParams() {
        return Collections.unmodifiableMap(bodyParams);
    }

    public void addBodyParam(String key, String value) {
        this.bodyParams.put(key, value);
    }

    public Map<String, String> getHeaders() {
        return Collections.unmodifiableMap(headers);
    }

    public void addHeader(String key, String value) {
        this.headers.put(key, value);
    }

    public Map<String, String> getAllParams() {
        Map<String, String> allParams = new HashMap<>();
        allParams.putAll(urlParams);
        allParams.putAll(bodyParams);
        return Collections.unmodifiableMap(allParams);
    }

    public String getParam(String name) {
        if (bodyParams.containsKey(name)) {
            return bodyParams.get(name);
        }
        return urlParams.get(name);
    }
}